#include <vtkLODActor.h>

class CFMaptors {
	private:
	int nMaptors;
	int MAXNMAPTORS;
	vtkPolyDataMapper **mappers;
	vtkLODActor **actors;
	vtkStripper **strippers;
	
	public:
	CFMaptors(CFList *cflist, int nMax = 10);
	void AddCF(CFList *cflist, int n);
	void DelCF(int n);
	vtkLODActor * GetActor(int n = 0);
};

CFMaptors::CFMaptors(CFList *cflist, int nMax) : MAXNMAPTORS(nMax) {
	mappers = new vtkPolyDataMapper*[MAXNMAPTORS];
	actors = new vtkLODActor*[MAXNMAPTORS];
	strippers = new vtkStripper*[MAXNMAPTORS];
	int ncf = cflist->GetnIso();
	nMaptors = 0;
	for(int i = 0; i < ncf; i++) {
		AddCF(cflist, i);
	}	
}

void CFMaptors::AddCF(CFList *cflist, int n) {
	vtkStripper *stripper = vtkStripper::New();
	stripper->SetInputConnection(cflist->GetOutput(n));
	strippers[nMaptors] = stripper;
	
	vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
	mapper->SetInputConnection(stripper->GetOutputPort());
	mapper->ScalarVisibilityOff();
	mappers[nMaptors] = mapper;
	
	vtkLODActor *actor = vtkLODActor::New();
	actor->SetMapper(mapper);
	actor->SetNumberOfCloudPoints(50000);
	actor->GetProperty()->SetOpacity(cflist->GetIsoOpacity(n));
	double *c = cflist->GetIsoColor(n);
	actor->GetProperty()->SetColor(c[0],c[1],c[2]);
	delete[] c;
	actors[nMaptors] = actor;
	
	nMaptors++;
}

void CFMaptors::DelCF(int n) {
	mappers[n]->Delete();
	actors[n]->Delete();
	strippers[n]->Delete();
	for(int i = n; i < nMaptors; i++) {
		mappers[i] = mappers[i+1];
		actors[i] = actors[i+1];
		strippers[i] = strippers[i+1];
	}
	nMaptors--;
}

vtkLODActor * CFMaptors::GetActor(int n) {
	return actors[n];
}
